<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>密件上传</title>
    <link rel="stylesheet" href="/css/common.css" type="text/css">
    <script src="/js/jquery/jquery-3.4.1.js"></script>
    <script src="/js/service/common.js"></script>
    <script>
        defaultBackPage();
        function saveFile(){
            let userIds = [];
            $("input[type=checkbox]").each((index, obj) => userIds.push(obj.value));
            var formData = new FormData($("#form")[0]);
            formData.append("consumers", userIds);
            $.ajax({
                url: "/file/secretUpload",
                type: "POST",
                data: formData,
                dataType: 'json',
                cache: false,
                processData: false,
                contentType: false,
                success: function (json) {
                    if(json.code === 200){
                        alert("保存成功！！！");
                        window.location.href="/page/service/file/secretFileList";
                    }else{
                        tipsMessage(json);
                    }
                }
            })
        }
        let openConsumer = 1;
        function chooseConsumer(obj) {
            let o = $(obj);
            if(openConsumer === 1){
                o.val("关闭接收人");
                o.css("background-color", "black");
                $("#consumer").css("display", "block");
                openConsumer = 2;
                $.ajax({

                });
            }else{
                o.val("选择接收人");
                o.css("background-color", "blue");
                $("#consumer").css("display", "none");
                openConsumer = 1;
            }
        }
    </script>
</head>
<body>
    <object class="object-top" data="/page/common/top"></object>
    <div>
        <div class="center-div">
            <form id="form" method="post" action="/file/upload" enctype="multipart/form-data">
                <table border="0" style="margin: auto">
                    <tr>
                        <td>
                            <label>
                                文件：
                            </label>
                        </td>
                        <td>
                            <label>
                                <input id="file" type="file" name="file">
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>
                                描述：
                            </label>
                        </td>
                        <td>
                            <label>
                                <textarea name="fileDesc" rows="5" placeholder="文件描述"></textarea>
                            </label>
                        </td>
                    </tr>
                </table>
                <label>
                    <input type="button" class="lang-btn" value="选择接收人" onclick="chooseConsumer(this)">
                </label><br>
                <label id="consumer" style="display: none">
                    <input type="checkbox" value="1">张三
                    <input type="checkbox" value="2">李四
                    <input type="checkbox" value="3">王五<br>
                    <input type="checkbox" value="4">张三
                    <input type="checkbox" value="5">李四
                    <input type="checkbox" value="6">王五
                </label><br>
                <label><input type="button" class="btn" value="上传" onclick="saveFile()"></label>
            </form>
        </div>
    </div>
</body>
</html>